package com.sk.cardeal.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.cardeal.R;
import com.sk.cardeal.callback.SelectBrandCallback;
import com.sk.cardeal.entity.ByPartsKindList;
import com.sk.cardeal.entity.CheckEntity;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by sk on 2018/3/29.
 */

public class ByPartsAdapter extends BaseQuickAdapter<ByPartsKindList.ResultListBean,BaseViewHolder> {

    public ByPartsAdapter(int layoutResId, @Nullable List<ByPartsKindList.ResultListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, ByPartsKindList.ResultListBean item) {
        helper.setText(R.id.original,item.getBrandName());
        if(item.isCheck()){
            helper.setChecked(R.id.original,true);
        }else {
            helper.setChecked(R.id.original,false);
        }

        final CheckBox checkBox = helper.getView(R.id.original);
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(checkBox.isChecked()){
                    EventBus.getDefault().post(new CheckEntity(helper.getAdapterPosition(),true));
                }else{
                    EventBus.getDefault().post(new CheckEntity(helper.getAdapterPosition(),false));
                }
            }
        });
    }
}
